package com.starlink.controller.wechat;

import com.starlink.common.WebResponse;
import com.starlink.common.annotation.WebAccess;
import com.starlink.common.PageInfoTwo;
import com.starlink.model.request.UserProductCollectRequest;
import com.starlink.model.request.save.UserProductCollectSaveRequest;
import com.starlink.service.UserProductCollectService;
import com.starlink.model.vo.UserProductCollectVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.validation.Valid;

/**
 * @author zhanghong
 */
@RestController
@RequestMapping("/wechat/collect")
@Api(value = "【小程序端】商品收藏模块", tags = {"【小程序端】商品收藏模块"})
public class WechatProductCollectController {

    @Autowired
    private UserProductCollectService userProductCollectService;

    @WebAccess(login = true)
    @ApiOperation("我的收藏—分页查询")
    @PostMapping("/pageQuery")
    public WebResponse<PageInfoTwo<UserProductCollectVO>> pageQuery(@RequestBody UserProductCollectRequest request) {
        return WebResponse.build(userProductCollectService.pageQuery(request));
    }

    @WebAccess(login = true)
    @ApiOperation("收藏新增")
    @PostMapping("/add")
    public WebResponse<Integer> add(@Valid @RequestBody UserProductCollectSaveRequest request) {
        return WebResponse.build(userProductCollectService.add(request));
    }

    @WebAccess(login = true)
    @ApiOperation("收藏删除")
    @PostMapping("/delete")
    public WebResponse<Boolean> deleteByKey(@RequestParam("ids") String ids) {
        return WebResponse.build(userProductCollectService.deleteDOByIds(ids));
    }
}
